<style>
table{
	width: 100%;
}
#delivery-order-ticket-model-form textarea{
	width: 300px;
	height: 55px;
}
#delivery-order-ticket-model-form input[type="text"]{
	width: 300px;
}
.lradio span input,.lradio span label{
	float: left;
	margin-right: 5px; 
}
</style>
<?php
$this->beginWidget('webroot.widgets.iButtonBar');
$this->widget('bootstrap.widgets.TbButton', array(
    'label'=>Yii::t('main','Update'),
    'type'=>'primary',
	'icon'=>'pencil white',
    'url'=> array('update', 'id'=>$model->id),
));
$this->widget('bootstrap.widgets.TbButton', array(
    'label'=>Yii::t('main', 'Close'),
    'type'=>'primary',
	'icon'=>'remove-sign white',
    'url'=> Yii::app()->createUrl('/delivery/deliveryOrderTicket/admin'),
));
$this->endWidget();
?>

<?php 
$this->beginWidget('webroot.widgets.iPortlet', array('title'=>Yii::t('main','View').' #'.$model->id));
?>
<?php if($updateTour==1):?>

<div class="hanhtrinh">
<div class="list-tour grid-view X-igrid">
<?php if($orderTour):?>
<table class="items itable">
<thead>
	<tr><th>Ngày cập nhật</th><th>Bưu cục nhận</th><th>Hành động</th><th>Bưu cục chuyển tiếp</th><th>Bưu tá</th><th>Lý do</th></tr>
</thead>
<?php foreach ($orderTour as $key => $value):?>
<tr>
	<td><?php echo date('d-m-Y H:i:s',strtotime($value->created_datetime));?></td>
	<td><?php echo OfficeModel::model()->findByPk($value->office_id)->name;?></td>
	<td><?php 
	switch ($value->status)
	{
		case 1:
			echo DeliveryMoveDetailModel::STATUS_1;
			break;
		case 2:
			echo DeliveryMoveDetailModel::STATUS_2;
			break;
		case 3:
			echo DeliveryMoveDetailModel::STATUS_3;
			break;
		default:
			echo DeliveryMoveDetailModel::STATUS_0;
			break;
	}
	?></td>
	<td>
		<?php if($value->office_next>0) echo OfficeModel::model()->findByPk($value->office_next)->name;?>
	</td>
	<td><?php if($value->office_user_id>0) echo BackendUsersModel::model()->findByPk($value->office_user_id)->username;?></td>
	<td><?php echo $value->reason;?></td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>
</div>
<?php 
$actionS = DeliveryMoveDetailModel::model()->getLastStatus($model->id);
?>
<?php if($actionS<=0):?>
	<h4>Cập nhật Hành trình của phiếu gửi <?php echo $model->code?></h4>
	<?php if(Yii::app()->user->hasFlash('message')):?>
	<div><?php echo Yii::app()->user->getFlash('message');?></div>
	<?php endif;?>
	<div class="form">
		<?php $form = $this->beginWidget('GxActiveForm', array(
			'id' => 'delivery-move-detail-model-form',
			'enableAjaxValidation' => false,
		));
		?>
		<div><i>Bưu cục: <?php echo OfficeModel::model()->findByPk(Yii::app()->user->office_id)->name;?></i></div>
		<div><i>Ngày cập nhật: <?php echo date('d/m/Y');?> Lúc <?php echo date('H:i:s');?></i></div>
		<?php echo $form->errorSummary($moveDetail); ?>
		<table class="lradio">
			<tr>
				<td width="70"><label>Hành động:</label></td>
				<td>
				<?php 
				$data = array(
						0=>'<span style="font-size: 11px">Phân công phát</span>',
						1=>'<span style="font-size: 11px">Chuyển tiếp</span>',
						2=>'<span style="font-size: 11px">Chuyển hoàn</span>',
						3=>'<span style="font-size: 11px">Hoàn thành</span>',
				);
				echo $form->radioButtonList($moveDetail, 'status', $data, array('separator'=>'&nbsp;', 'onclick'=>'TransferChoice(this.value)')); 
				?>
				</td>
			</tr>
		</table>
		<div id="result">
			<span>Bưu tá:</span>
			<?php 
			if($this->role!='Administrator'){
				$listData = array(Yii::app()->user->id=>Yii::app()->user->username);
			}else
				$listData = CHtml::listData(BackendUsersModel::model()->findAll(), 'id', 'username');	
			echo CHtml::dropDownList('office_user', '', $listData);
			?>
		</div>
		<?php echo $form->hiddenField($moveDetail, 'order_ticket_id', array('value'=>$model->id));?>
		<?php echo $form->hiddenField($moveDetail, 'office_id', array('value'=>Yii::app()->user->office_id));?>
		<?php
		echo GxHtml::submitButton(Yii::t('app', 'Save'),array('class'=>'btn btn-success'));
		$this->endWidget();
		?>
	</div>
	<?php else:?>
	<h1>Đã chuyển phát thành công!</h1>
	<?php endif;?>
</div>
<?php endif;?>
<?php
$this->widget('zii.widgets.CDetailView', array(
		'data' => $model,
		'attributes' => array(
				'id',
				'code',
				'air_bill',
				array(
						'name'=>'customer_id',
						'value'=>DeliveryCustomerModel::model()->findByPk($model->customer_id)->name
				),
				'receive_address',
				array(
						'name'=>'office',
						'value'=>OfficeModel::model()->findByPk($model->office)->name
				),
				'address',
				array(
						'name'=>'payment',
						'value'=>PaymentModel::model()->findByPk($model->payment)->name
				),
				array(
						'name'=>'weight',
						'value'=>$model->weight.' gam'
				),
				array(
						'name'=>'service',
						'value'=>DeliveryServicesModel::model()->findByPk($model->service)->name
				),
				'content',
				'charge_pri',
				'charge_more',
				'vat',
				'total',
		),
));
$this->endWidget();
?>
<script>
function TransferChoice(val)
{
	$.ajax({
		url: '<?php echo Yii::app()->createUrl('/delivery/deliveryOrderTicket/getActionTransfer')?>',
		type: 'post',
		data: {type:val},
		beforeSend: function(){
			var load = '<img width="16" src="<?php echo Yii::app()->theme->baseUrl?>/images/ajax-loader.gif" />';
			$("#result").html(load);
		},
		success: function(data){
			$("#result").html(data);
		}
		})
}
</script>
